package com.bot.nft.module.dc.api;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bot.auth.core.pojo.SaBaseClientLoginUser;
import com.bot.auth.core.util.StpClientLoginUserUtil;
import com.bot.common.pojo.CommonResult;
import com.bot.nft.module.dc.domain.bo.DcOrderQueryBo;
import com.bot.nft.module.dc.domain.vo.DcOrderInfoVo;
import com.bot.nft.module.dc.service.IDcOrderInfoService;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 描述:
 * 时间: 2024-01-29 09:14
 * 负责人: 任晓政
 **/
@RestController
@RequestMapping("/app/order")
@CrossOrigin
public class AppDcOrderInfoController {

    @Resource
    IDcOrderInfoService dcOrderService;

    //分页查询藏品订单信息
    @RequestMapping("/{pageNo}/{pageSize}/queryDcOrder.do")
    public CommonResult<Page> selectDcBill(@RequestBody DcOrderQueryBo dcOrderQueryBo, @PathVariable("pageNo") Integer pageNo, @PathVariable("pageSize") Integer pageSize) {
        //调用接口
        Page<DcOrderInfoVo> dcOrderInfoVoPageInfo = dcOrderService.queryDcOrderInfo(dcOrderQueryBo.getId(), dcOrderQueryBo.getPhone(), dcOrderQueryBo.getName(), dcOrderQueryBo.getStatus(), pageNo, pageSize);
        CommonResult<Page> commonResult = new CommonResult<>();
        if (ObjectUtil.isNotNull(dcOrderInfoVoPageInfo)) {
            commonResult.setMsg("操作成功");
            commonResult.setCode(200);
            commonResult.setData(dcOrderInfoVoPageInfo);
        } else {
            commonResult.setMsg("操作失败");
            commonResult.setCode(500);
        }
        return commonResult;
    }

    //查看藏品订单信息
    @RequestMapping("/{id}/getDcOrder.do")
    public CommonResult<DcOrderInfoVo> getDcSell(@PathVariable("id") String id) {
        //调用接口
        DcOrderInfoVo dcOrderInfo = dcOrderService.getDcOrderInfo(id);
        CommonResult<DcOrderInfoVo> commonResult = new CommonResult<>();
        if (ObjectUtil.isNotNull(dcOrderInfo)) {
            commonResult.setMsg("操作成功");
            commonResult.setCode(200);
            commonResult.setData(dcOrderInfo);
        } else {
            commonResult.setMsg("操作失败");
            commonResult.setCode(500);
        }
        return commonResult;
    }

    //购买藏品【下单】
    @RequestMapping("/buyDcOrder.do")
    public CommonResult<DcOrderInfoVo> buyDcNft(HttpServletRequest request, @Param("id") String id) {
        //从请求头中获取令牌
        SaBaseClientLoginUser clientLoginUser = StpClientLoginUserUtil.getClientLoginUser();
        String mbId = clientLoginUser.getId();
        DcOrderInfoVo dcOrderInfoVo = dcOrderService.buyDcNftInfo(id, mbId);
        CommonResult<DcOrderInfoVo> commonResult = new CommonResult<>();
        if (ObjectUtil.isNotNull(dcOrderInfoVo)) {
            commonResult.setMsg("操作成功");
            commonResult.setCode(200);
            commonResult.setData(dcOrderInfoVo);
        } else {
            commonResult.setMsg("操作失败");
            commonResult.setCode(500);
        }
        return commonResult;
    }

    //支付藏品
    //购买藏品【支付】
    @RequestMapping("/{id}/paymentNft.do")
    public CommonResult paymentNft(@PathVariable("id") String id) {
        Boolean boo = dcOrderService.paymentDcNftInfo(id);
        CommonResult commonResult = new CommonResult<>();
        if (boo) {
            commonResult.setMsg("操作成功");
            commonResult.setCode(200);
        } else {
            commonResult.setMsg("操作失败");
            commonResult.setCode(500);
        }
        return commonResult;
    }


}
